﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class wsd_2 : FormBase1
    {
        BindingList<SVC.client.wsd> ds;
        BindingList<SVC.client.View_Emp_lite> emps;
        BindingList<SVC.client.kf_dls> dlss;
        BindingList<SVC.client.kf_tc> tcs;
        BindingList<SVC.client.ywxz> ywxzs;
        SVC.client.wsd v;
        public wsd_2()
        {
            InitializeComponent();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (gridView1.FocusedRowHandle >= 0)
            {
                v = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.wsd;
                te_pid.Text = v.pid;
                te_jrh.Text = v.jrh;
                lue_dls.EditValue = v.dlsid;
                te_yhmc.Text = v.yhmc;

            }
            else
            {
                resetui();
            }
        }

        private void resetui()
        {
            v = null;
            te_pid.Text = "";
            te_jrh.Text = "";
            lue_dls.EditValue = null;
            te_yhmc.Text = "";

            sp_ldjfje.EditValue = 0;

            te_gdbz.Text = "";
            te_xcsj.Text = "";
            lue_ldr.EditValue = null;
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            ds.Clear();
            int? dlsid = null;
            DateTime? sd = null;
            DateTime? ed = null;
            if (lue_dls.EditValue!=null)
            {
                dlsid = int.Parse(lue_dls.EditValue.ToString());
            }
            if (dateselect1.de_sd.EditValue!=null&&dateselect1.de_ed.EditValue!=null)
	        {
                sd=dateselect1.de_sd.DateTime;
                ed=dateselect1.de_ed.DateTime;
	        }
            foreach (SVC.client.wsd item in my.bw.wsd_get_By(dlsid, sd, ed, te_s_jrh.Text.Trim(), te_s_yhmc.Text.Trim(),1, my.ACID))
            {
                ds.Add(item);
            }
        }

        private void wsd_1_Load(object sender, EventArgs e)
        {
            ds = new BindingList<SVC.client.wsd>();
            emps = my.bw.View_Emp_lite_List("", my.ACID);
            dlss=my.bw.kf_dls_Get("",my.ACID);
            tcs=my.bw.kf_tc_Get("",my.ACID);
            ywxzs=my.bw.ywxz_Get("",my.ACID);
            lue_ldr.Properties.DataSource = emps;
            rlue_dls.DataSource = dlss;
            rlue_jsr.DataSource = emps;
            rlue_tc.DataSource = tcs;
            rlue_ywxz.DataSource = ywxzs;
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (v!=null)
            {
                if (!dvp.Validate())
                {
                    v.ldjfje = Convert.ToDecimal(sp_ldjfje.EditValue);
                    v.gdbz = te_gdbz.Text;
                    v.xcsj = te_xcsj.Text;
                    v.ldr = new Guid(lue_ldr.EditValue.ToString());
                    string r = my.bw.wsd_Update(v, my.ACID);
                    if (!string.IsNullOrEmpty(r))
                    {

                        Comm.ShowErorr(r);
                    }
                    else
                    {
                        Comm.ShowInfo("单据保存成功！");
                        ds.Remove(v);
                        resetui();
                    }
                }

            }
        }


    }
}